{{--继承模板--}}
@extends('admin.layouts.common')
@section('content')
    <style type="text/css">
        ul.ztree li span.button.switch{margin-right:5px}
        ul.ztree>li{background: #dae6f0;padding: 8px;}
        ul.ztree>li ul li{background: #eef5fa;margin-top: 8px;padding: 5px;}
        ul.ztree>li ul li ul li{background: #f6fbff;padding: 5px;}
        ul.ztree>li ul li ul li ul li{background: #fff;padding: 5px;}
        ul.ztree ul ul ul li{display:inline-block;}
        ul.ztree>ul li>ul>li{padding:5px}
        ul.ztree>ul li>ul{margin-top:12px}
        ul.ztree>ul li{padding:15px;padding-right:25px}
        ul.ztree>ul li{white-space:normal!important;background: #01AAED}
        ul.ztree li{white-space:inherit;}
        ul.ztree>li>a>span{font-size:15px;font-weight:700}
    </style>
    <link rel="stylesheet" href="{{asset('admin/zTree/css/zTreeStyle.css')}}" type="text/css">
    <div class="layui-anim layui-anim-upbit headalert" style="margin: -15px -20px;">
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane">
                <ul id="treeDemo" class="ztree"></ul>
                <div class="layui-form-item text-center" align="center" style="margin-top: 20px;">
                    <button type="button" class="layui-btn layui-btn-black" lay-submit="" lay-filter="submit">提交</button>
                </div>
            </form>
        </div>
    </div>
    <script src="{{asset('layuiadmin/layui/layui.js')}}"></script>
    <script type="text/javascript" src="{{asset('admin/js/jquery.2.1.1.min.js')}}"></script>
    <script type="text/javascript" src="{{asset('admin/zTree/js/jquery.ztree.core.min.js')}}"></script>
    <script type="text/javascript" src="{{asset('admin/zTree/js/jquery.ztree.excheck.min.js')}}"></script>
    <script type="text/javascript">
        var setting = {
            check:{enable: true},
            view: {showLine: false, showIcon: false, dblClickExpand: false},
            data: {
                simpleData: {enable: true, pIdKey:'pid', idKey:'id'},
                key:{name:'title'}
            }
        };
        var zNodes = {!! $data !!};
        function setCheck() {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            zTree.setting.check.chkboxType = { "Y":"ps", "N":"ps"};

        }
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        setCheck();
        var _token =  $('meta[name="csrf-token"]').attr('content');
        layui.use(['form', 'layer'], function () {
            var form = layui.form, layer = layui.layer;
            form.on('submit(submit)', function () {
                // 提交到方法 默认为本身
                var treeObj=$.fn.zTree.getZTreeObj("treeDemo"),
                    nodes=treeObj.getCheckedNodes(true),
                    v="";
                for(var i=0;i<nodes.length;i++){
                    v+=nodes[i].id + ",";
                }
                var id = "{{$idinfo}}";
                $.post("{{url('admin/auth/groupaccess')}}", {'rules':v,'group_id':id,_token:_token}, function (res) {
                    if (res.code > 0) {
                        layer.msg(res.msg);
                        setTimeout(function(){
                            window.parent.location.reload();//修改成功后刷新父界面
                        },  1000);
                    } else {
                        layer.msg(res.msg);
                    }
                });
            })
        });
    </script>
@endsection